package easy;

public class LongestCommonPrefix {
	public static void main(String[] args) {
		String[] strs = new String[2];
		strs[0] = new String("c");
		strs[1] = new String("c");;
		System.out.println(new LongestCommonPrefix().longestCommonPrefix(strs));
	}
	public String longestCommonPrefix(String[] strs) {
		String temp = "";
		if (strs != null)
			if (strs.length != 0) {
				temp = strs[0];
				for (int i = 1; i < strs.length; i++) {
					int len1 = temp.length();
					int len2 = strs[i].length();
					int smlLen = len1 > len2 ? len2 : len1;
					int j = 0;
					for (j = 0; j < smlLen; j++) {
						if (strs[i].charAt(j) != temp.charAt(j))
							break;
					}
					temp = temp.substring(0, j);
				}
			}
		return temp;
	}
}
